#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/Gateway/Gateway.UI.Api/nuget.config", "src/Gateway/Gateway.UI.Api/"]
COPY ["src/Gateway/Gateway.UI.Api/Gateway.UI.Api.csproj", "src/Gateway/Gateway.UI.Api/"]

COPY ["src/AI/Aurora.AI.Common/Aurora.AI.Common.csproj", "src/AI/Aurora.AI.Common/"]
COPY ["src/AI/Gateway/Aurora.AI.Abstractions/Aurora.AI.Abstractions.csproj", "src/AI/Gateway/Aurora.AI.Abstractions/"]
COPY ["src/AI/Gateway/Aurora.AI.Gateway/Aurora.AI.Gateway.csproj", "src/AI/Gateway/Aurora.AI.Gateway/"]
COPY ["src/Components/Redis/Aurora.Redis/Aurora.Redis.csproj", "src/Components/Redis/Aurora.Redis/"]
COPY ["src/AI/Gateway/Domain/Aurora.AI.Domain/Aurora.AI.Domain.csproj", "src/AI/Gateway/Domain/Aurora.AI.Domain/"]
COPY ["src/AI/SqlSugar/Aurora.AI.SqlSugar.Framework/Aurora.AI.SqlSugar.Framework.csproj", "src/AI/SqlSugar/Aurora.AI.SqlSugar.Framework/"]
COPY ["src/AI/Gateway/Extensions/Aurora.AI.MetaGLM/Aurora.AI.MetaGLM.csproj", "src/AI/Gateway/Extensions/Aurora.AI.MetaGLM/"]
COPY ["src/AI/Wiki/Aurora.AI.Wiki/Aurora.AI.Wiki.csproj", "src/AI/Wiki/Aurora.AI.Wiki/"]
COPY ["src/AI/Wiki/Aurora.AI.Wiki.Domain/Aurora.AI.Wiki.Domain.csproj", "src/AI/Wiki/Aurora.AI.Wiki.Domain/"]


COPY ["src/Components/HttpClients/Aurora.HttpClient/Aurora.HttpClient.csproj", "src/Components/HttpClients/Aurora.HttpClient/"]
COPY ["src/Components/HttpClients/Discovery/Aurora.Discovery.HttpClient.Abstractions/Aurora.Discovery.HttpClient.Abstractions.csproj", "src/Components/HttpClients/Discovery/Aurora.Discovery.HttpClient.Abstractions/"]
COPY ["src/Components/HttpClients/Discovery/Aurora.Discovery.HttpClient.Nacos/Aurora.Discovery.HttpClient.Nacos.csproj", "src/Components/HttpClients/Discovery/Aurora.Discovery.HttpClient.Nacos/"]
COPY ["src/Components/SingalR/Aurora.SingalR/Aurora.SingalR.csproj", "src/Components/SingalR/Aurora.SingalR/"]
COPY ["src/Components/SlideCaptcha/Aurora.SlideCaptcha/Aurora.SlideCaptcha.csproj", "src/Components/SlideCaptcha/Aurora.SlideCaptcha/"]
COPY ["src/Components/TaskScheduler/Aurora.TaskScheduler.Abstractions/Aurora.TaskScheduler.Abstractions.csproj", "src/Components/TaskScheduler/Aurora.TaskScheduler.Abstractions/"]
COPY ["src/Components/TaskScheduler/Aurora.TaskScheduler.DistributedLock/Aurora.TaskScheduler.DistributedLock.csproj", "src/Components/TaskScheduler/Aurora.TaskScheduler.DistributedLock/"]
COPY ["src/Components/TaskScheduler/Dashboard/Aurora.TaskScheduler.Dashboard/Aurora.TaskScheduler.Dashboard.csproj", "src/Components/TaskScheduler/Dashboard/Aurora.TaskScheduler.Dashboard/"]
COPY ["src/Components/TaskScheduler/Aurora.TaskScheduler.Extension/Aurora.TaskScheduler.Extension.csproj", "src/Components/TaskScheduler/Aurora.TaskScheduler.Extension/"]
COPY ["src/Components/TaskScheduler/Storage/Aurora.TaskScheduler.Storage.MySql/Aurora.TaskScheduler.Storage.MySql.csproj", "src/Components/TaskScheduler/Storage/Aurora.TaskScheduler.Storage.MySql/"]


COPY ["src/FileServer/FileServer.Abstractions/FileServer.Abstractions.csproj", "src/FileServer/FileServer.Abstractions/"]
COPY ["src/FileServer/FileServer.Extension/FileServer.Extension.csproj", "src/FileServer/FileServer.Extension/"]
COPY ["src/FileServer/FileServer.Storage.MySql/FileServer.Storage.MySql.csproj", "src/FileServer/FileServer.Storage.MySql/"]


COPY ["src/Gateway/Application/Gateway.Application/Gateway.Application.csproj", "src/Gateway/Application/Gateway.Application/"]
COPY ["src/Gateway/Domain/Gateway.Domain/Gateway.Domain.csproj", "src/Gateway/Domain/Gateway.Domain/"]
COPY ["src/Components/Security/Aurora.Security/Aurora.Security.csproj", "src/Components/Security/Aurora.Security/"]
COPY ["src/Gateway/Common/Gateway.Common/Gateway.Common.csproj", "src/Gateway/Common/Gateway.Common/"]
COPY ["src/Gateway/Infrastructure/Gateway.Infrastructure/Gateway.Infrastructure.csproj", "src/Gateway/Infrastructure/Gateway.Infrastructure/"]
COPY ["src/Components/Core/AbpModules/AbpModules.csproj", "src/Components/Core/AbpModules/"]
COPY ["src/Gateway/Domain/Gateway.IRepositories/Gateway.IRepositories.csproj", "src/Gateway/Domain/Gateway.IRepositories/"]
COPY ["src/Gateway/Application/Gateway.IApplication/Gateway.IApplication.csproj", "src/Gateway/Application/Gateway.IApplication/"]
COPY ["src/Gateway/Common/Core.Ali/Core.Ali.csproj", "src/Gateway/Common/Core.Ali/"]
COPY ["src/Gateway/Common/Core.MediatR/Core.MediatR.csproj", "src/Gateway/Common/Core.MediatR/"]
COPY ["src/Gateway/Common/Gateway.Apollo/Gateway.Apollo.csproj", "src/Gateway/Common/Gateway.Apollo/"]
COPY ["src/Gateway/Common/Gateway.Logger/Gateway.Logger.csproj", "src/Gateway/Common/Gateway.Logger/"]
COPY ["src/Gateway/Common/Gateway.OpenTelemetry/Gateway.OpenTelemetry.csproj", "src/Gateway/Common/Gateway.OpenTelemetry/"]
COPY ["src/Gateway/Domain/Gateway.SqlSugar/Gateway.SqlSugar.csproj", "src/Gateway/Domain/Gateway.SqlSugar/"]
COPY ["src/Gateway/Query/Gateway.IQuery/Gateway.IQuery.csproj", "src/Gateway/Query/Gateway.IQuery/"]
COPY ["src/Gateway/Query/Gateway.Query/Gateway.Query.csproj", "src/Gateway/Query/Gateway.Query/"]
RUN dotnet restore "./src/Gateway/Gateway.UI.Api/Gateway.UI.Api.csproj"
COPY . .
WORKDIR "/src/src/Gateway/Gateway.UI.Api"
RUN dotnet build "./Gateway.UI.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Gateway.UI.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
USER root
WORKDIR /app
COPY --from=publish /app/publish .
RUN chmod 777 /app
RUN chmod a+x /app/appsettings/Seed/*
ENTRYPOINT ["dotnet", "Gateway.UI.Api.dll","--urls=http://0.0.0.0:80"]